package com.wyd.observer.demo03;

import com.wyd.observer.demo02.Observer.Display;
import com.wyd.observer.demo02.Subject.Subject;

import java.util.Observable;
import java.util.Observer;

/**
 * @author Yudi Wang
 * @date 2022/1/6 11:24
 */
public class PressureDisplay implements Observer, Display {

    private int pressure;

    public PressureDisplay(Observable subject) {
        subject.addObserver(this);
    }

    public void update(Observable o, Object arg) {
        if (o instanceof com.wyd.observer.demo03.WeatherData) {
            com.wyd.observer.demo03.WeatherData weatherData = (WeatherData) o;
            this.pressure = weatherData.getPressure();
            display();
        }
    }

    public void display() {
        System.out.println("当前气压为：" + pressure);
    }
}
